package org.example.atry.myservlet;

import jakarta.servlet.GenericServlet;
import jakarta.servlet.ServletException;
import jakarta.servlet.ServletRequest;
import jakarta.servlet.ServletResponse;
import jakarta.servlet.annotation.WebServlet;
import jakarta.servlet.http.HttpServletRequest;
import jakarta.servlet.http.HttpServletResponse;
import org.example.atry.service.agricultuerserv;
import org.example.atry.service.impl.aserviced;
import org.json.JSONObject;

import java.io.IOException;
import java.io.PrintWriter;

@WebServlet(urlPatterns = {"/delet"})
public class delet extends GenericServlet {
    @Override
    public void service(ServletRequest servletRequest, ServletResponse servletResponse) throws ServletException, IOException {
        HttpServletRequest request = (HttpServletRequest) servletRequest;
        HttpServletResponse response = (HttpServletResponse) servletResponse;
        // 设置允许跨域的头部信息
        response.setHeader("Access-Control-Allow-Origin", "*");
        response.setHeader("Access-Control-Allow-Methods", "GET, POST, PUT, DELETE");
        response.setHeader("Access-Control-Allow-Headers", "Content-Type");
        response.setHeader("Access-Control-Max-Age", "3600");
        String username = request.getParameter("username");
        String password = request.getParameter("password");
        agricultuerserv aserviced=new aserviced();
        Integer as=aserviced.delete(username,password);

//System.out.println(as);
        JSONObject obj=new JSONObject();
        obj.put("as",as);
        PrintWriter out=response.getWriter();
        out.print(obj.toString());
        out.flush();
//        if(as==1){
////            response.sendRedirect("./ajax/dele.html");
////            response.getWriter().print(as);
//
//
//        }else {
//            response.sendRedirect("./ajax/dele.html");
//        }
  }
}
